<?php

/**
 * Description of SignupService
 *
 * @author Adam
 */
class AccessPageService {
    private static $instance = null;

    public static function getInstance() {
       if (!self::$instance instanceof self) {
         self::$instance = new self;
       }
       return self::$instance;
    }

    public function __destruct() {
    }

    public function getAccessPages($DBprefix,$show) {
        $show = mysql_escape_string($show);
        $query = "SELECT * FROM `".$DBprefix."access_pages` WHERE `pagename` = '$show'";
        $queryResult = mysql_query($query);
        
        $accessPage = new AccessPage();
        if ($accesspage_info = mysql_fetch_array($queryResult)){ 
            $accessPage->setId( $accesspage_info["pageid"] );
            $accessPage->setName( $accesspage_info["pagename"] );
            $accessPage->setPerm( $accesspage_info["pageperm"] );
            $accessPage->setSub( $accesspage_info["pagesub"] );
        }
        
        return $accessPage;
    }

    public function getAccessPagesByPageId($DBprefix,$pageId) {
        $show = mysql_escape_string($show);
        $query = "SELECT * FROM `".$DBprefix."access_pages` WHERE `pageid` = '$pageId'";
        $queryResult = mysql_query($query);
        
        $accessPage = new AccessPage();
        if ($accesspage_info = mysql_fetch_array($queryResult)){ 
            $accessPage->setId( $accesspage_info["pageid"] );
            $accessPage->setName( $accesspage_info["pagename"] );
            $accessPage->setPerm( $accesspage_info["pageperm"] );
            $accessPage->setSub( $accesspage_info["pagesub"] );
        }
        
        return $accessPage;
    }

    public function getAllOrderLimit($DBprefix,$orderBy,$begin,$rowsOnPage) {
        $show = mysql_escape_string($show);
        $query = "SELECT * FROM `" . $DBprefix . "access_pages` ORDER BY `$orderBy` DESC LIMIT $begin,$rowsOnPage";
        $queryResult = mysql_query($query);
        
        $pages = array();
        while ($accesspage_info = mysql_fetch_array($queryResult)){ 
            $accessPage = new AccessPage();
            $accessPage->setId( $accesspage_info["pageid"] );
            $accessPage->setName( $accesspage_info["pagename"] );
            $accessPage->setPerm( $accesspage_info["pageperm"] );
            $accessPage->setSub( $accesspage_info["pagesub"] );
            $pages[] = $accessPage;
        }
        
        return $pages;
    }

    public function getAll($DBprefix) {
        $show = mysql_escape_string($show);
        $query = "SELECT * FROM `" . $DBprefix . "access_pages`";
        $queryResult = mysql_query($query);
        
        $pages = array();
        while ($accesspage_info = mysql_fetch_array($queryResult)){ 
            $accessPage = new AccessPage();
            $accessPage->setId( $accesspage_info["pageid"] );
            $accessPage->setName( $accesspage_info["pagename"] );
            $accessPage->setPerm( $accesspage_info["pageperm"] );
            $accessPage->setSub( $accesspage_info["pagesub"] );
            $pages[] = $accessPage;
        }
        
        return $pages;
    }

    public function getAccessPagesSub($DBprefix,$access_pagesname,$view) {
        $show = mysql_escape_string($show);
        $query = "SELECT * FROM `".$DBprefix."access_pages` WHERE `pagename` = '$access_pagesname' AND `pagesub` = '$view'";
        $queryResult = mysql_query($query);
        
        $accessPage = new AccessPage();
        if ($accesspage_info = mysql_fetch_array($queryResult)){ 
            $accessPage->setId( $accesspage_info["pageid"] );
            $accessPage->setName( $accesspage_info["pagename"] );
            $accessPage->setPerm( $accesspage_info["pageperm"] );
            $accessPage->setSub( $accesspage_info["pagesub"] );
        }
        
        return $accessPage;
    }
}

?>
